# Contributor: Alexandre Mutel <alexandre_mutel@live.com>
# Maintainer: Alexandre Mutel <alexandre_mutel@live.com>
pkgname=ktx
pkgver=4.3.2
pkgrel=0
pkgdesc="KTX (Khronos Texture) tools and libraries"
url="https://github.com/KhronosGroup/KTX-Software"
arch="all !s390x"
license="Apache-2.0"
depends="fmt $pkgname-libs"
depends_dev="$pkgname-libs"
makedepends="bash cmake samurai zstd-dev doxygen sdl2-dev mesa-dev vulkan-headers assimp-dev opencl-dev"
subpackages="$pkgname-dev $pkgname-libs"
source="$pkgname-$pkgver.tar.gz::https://github.com/KhronosGroup/KTX-Software/archive/refs/tags/v$pkgver.tar.gz
	ktx_override_version.patch
"
builddir="$srcdir/KTX-Software-$pkgver"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-DKTX_VERSION_FULL=v$pkgver \
		-DCMAKE_BUILD_TYPE=Release \
		-DKTX_FEATURE_TESTS=ON \
		$crossopts
	cmake --build build
}

libs() {
	pkgdesc="KTX (Khronos Texture) shared library"
	amove usr/lib/libktx*.so*
}

check() {
	build/Release/unittests
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
0077315fe2b4e676e97e3a158c2c6e1f6ba426e14ad23342592cd69be28cfce64c40614e0a84d58a9634877ab334e713b94d4c962132c98bfea308e91bc8a98a  ktx-4.3.2.tar.gz
e0e017f356e19be88a1a4cf0085ee2692d9d912b375501c1f5fad54a8377f73040f0c3fd7c243595c1708ae9933f0cb094661e51103b0a8785686c50547b23a2  ktx_override_version.patch
"
